home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_Tix.idb / usr / freeware / lib / tix4.1 / demos / samples / OptMenu.tcl.z / OptMenu.tcl
Encoding:
Text File  |  1999-01-26  |  2.9 KB  |  100 lines

  1. # Tix Demostration Program
  2. #
  3. # This sample program is structured in such a way so that it can be
  4. # executed from the Tix demo program "widget": it must have a
  5. # procedure called "RunSample". It should also have the "if" statment
  6. # at the end of this file so that it can be run as a standalone
  7. # program using tixwish.
  8.  
  9. # This file demonstrates the use of the tixOptionMenu widget -- you can
  10. # use it for the user to choose from a fixed set of options
  11. #
  12. set opt_options {text formatted post html tex rtf}
  13.  
  14. set opt_labels(text)        "Plain Text" 
  15. set opt_labels(formatted)    "Formatted Text"
  16. set opt_labels(post)        "PostScript"
  17. set opt_labels(html)        "HTML"
  18. set opt_labels(tex)        "LaTeX"
  19. set opt_labels(rtf)        "Rich Text Format"
  20.  
  21. proc RunSample {w} {
  22.     catch {uplevel #0 unset demo_opt_from}
  23.     catch {uplevel #0 unset demo_opt_to  }
  24.  
  25.     # Create the tixOptionMenu's on the top of the dialog box
  26.     #
  27.     frame $w.top -border 1 -relief raised
  28.  
  29.     tixOptionMenu $w.top.from -label "From File Format : " \
  30.     -variable demo_opt_from \
  31.     -options {
  32.         label.width  19
  33.         label.anchor e
  34.         menubutton.width 15
  35.     }
  36.  
  37.     tixOptionMenu $w.top.to -label "To File Format : " \
  38.     -variable demo_opt_to \
  39.     -options {
  40.         label.width  19
  41.         label.anchor e
  42.         menubutton.width 15
  43.     }
  44.  
  45.     # Add the available options to the two OptionMenu widgets
  46.     #
  47.     # [Hint] You have to add the options first before you set the
  48.     #         global variables "demo_opt_from" and "demo_opt_to". Otherwise
  49.     #         the OptionMenu widget will complain about "unknown options"!
  50.     #
  51.     global opt_options opt_labels
  52.     foreach opt $opt_options {
  53.     $w.top.from add command $opt -label $opt_labels($opt)
  54.     $w.top.to   add command $opt -label $opt_labels($opt)
  55.     }
  56.  
  57.     uplevel #0 set demo_opt_from html
  58.     uplevel #0 set demo_opt_to   post
  59.  
  60.     pack $w.top.from $w.top.to -side top -anchor w -pady 3 -padx 6
  61.  
  62.     # Use a ButtonBox to hold the buttons.
  63.     #
  64.     tixButtonBox $w.box -orientation horizontal
  65.     $w.box add ok     -text Ok     -underline 0 -command "opt:okcmd $w" \
  66.     -width 6
  67.     $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
  68.     -width 6
  69.  
  70.     pack $w.box -side bottom -fill x
  71.     pack $w.top -side top -fill both -expand yes
  72.  
  73.     # Let's set some nice bindings for keyboard accelerators
  74.     #
  75.     bind $w <Alt-f> "focus $w.top.from" 
  76.     bind $w <Alt-t> "focus $w.top.to" 
  77.     bind $w <Alt-o> "[$w.box subwidget ok] invoke; break" 
  78.     bind $w <Alt-c> "[$w.box subwidget cancel] invoke; break" 
  79. }
  80.  
  81. proc opt:okcmd {w} {
  82.     global demo_opt_from demo_opt_to opt_labels
  83.  
  84.     puts "You wanted to convert file from $opt_labels($demo_opt_from) to $opt_labels($demo_opt_to)"
  85.  
  86.     destroy $w
  87. }
  88.  
  89.  
  90. # This "if" statement makes it possible to run this script file inside or
  91. # outside of the main demo program "widget".
  92. #
  93. if {![info exists tix_demo_running]} {
  94.     wm withdraw .
  95.     set w .demo
  96.     toplevel $w
  97.     RunSample $w
  98.     bind $w <Destroy> {if {"%W" == ".demo"} exit}
  99. }
  100.